const express = require("express")
const app = express()

// 允许跨域
app.use(require('cors')())
// 
app.use(express.json())

// 连接数据库
const mongoose = require('mongoose')
mongoose.connect("mongodb://localhost:27017/daping", {
    useCreateIndex: true,
    useFindAndModify: true,
    useNewUrlParser: true,
})

const bigScreen = mongoose.model("dapingData", new mongoose.Schema({
}), 'dapingData')


app.get("/", async (req, res) =>
    res.send("restful page"))

// 查询所有数据
app.get("/api/dapingData", async (req, res) => {
    const dapingData = await bigScreen.find()
    res.send(dapingData)
})

app.listen(3000, () =>
    console.log("http://localhost:3000/")
)